<?php
	include "inc/userAuth.php";
	$rows = 4;
	$step = 1;
	if(isset($_GET['step'])){
		$step = $_GET['step'];
	}
	switch($step) {
		case 1:
			$id = 'linid';
			break;
		case 2:
			$id = 'rinid';
			break;
		case 3:
			$id = 'binid';
			break;
		default:
			$id = 'linid';
			break;
	}
	if($_SESSION[$id] != "") {
		include "conn/database.php";
		$sql = "SELECT * FROM `T_ESPOUSER_QUESTIONS_ANSWERS`
						WHERE INTERVIEW_SID = '".$_SESSION[$id]."'
						ORDER BY `T_ESPOUSER_QUESTIONS_ANSWERS`.`INDEX` ASC";
		$res = mysql_query($sql);
		$rows = mysql_num_rows($res);

		while($row = mysql_fetch_array($res)){
			$index = $row["INDEX"];
			$question[$index] = $row['QUESTION_FR'];
			$answer[$index] = $row['ANSWER_FR'];
		}
	} else {
		for($i = 1; $i <= $rows; $i++){
			$question[$i] = "";
			$answer[$i] = "";			
		}
	}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="Description" content="Une application mobile unique pour un mariage unique.">
<meta name="Keywords" content="wedding box, mariage, application mobile, appstore, google play, iphone, android, iphone 5, samsung galaxy s3, promesse d'une vie">
<title>Promesse d'une Vie</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<link type="text/css" rel="stylesheet" media="screen" href="css/style.css">
<script type="text/javascript" src="js/jquery-1.7.2.min.js" charset="utf-8"></script>
<script type="text/javascript" src="js/jquery.validate.min.js"></script>
<script type="text/javascript" src="js/wedding_form.js" charset="utf-8"></script>
<script type="text/javascript">
	function make_order() {
		size = $('.form_question_box').size();
		$('.form_question_box').each(function(){
			index = $('.form_question_box').index(this) + 1;
			//$(this).find('.form_text label').html('Question '+index+'<span class="star">*</span>');
			$(this).find('.form_text input').attr('name','Question'+index);
			//$(this).find('.form_textarea label').attr('for','A'+index).html('Réponse '+index+'<span class="star">*</span>');
			$(this).find('.form_textarea textarea').attr('name','A'+index);
		});
	}
	$().ready(function() {
		$('.btn-ques-add').click(function(){
			$('.form_question_box').last().after('\
				<div class="form_question_box" style="display:none">\
					<div class="form_question">\
						<div class="form_text">\
							<label>Question libre (Facultatif)</label>\
							<input type="text" name="Question5" placeholder="Ecrivez votre question" value=""/>\
						</div>\
						<div class="form_textarea">\
							<label for="A5">Réponse</label>\
							<textarea name="A5" cols="" rows=""></textarea>\
							<p class="below-desc">Champ libre</p>\
						</div>\
						<a class="btn-ques-cancel button">Annuler</a>\
					</div>\
				</div>').siblings('.form_question_box').last().slideDown();
				make_order();
		});
		$('.btn-ques-cancel').live('click',function(){
			$(this).closest('.form_question_box').slideUp(function() {
				$(this).closest('.form_question_box').detach();
				make_order();
			});
		});
	});
</script>
</head>

<body>	
	<div class="main-content">
		<?php
			include "left-menu.php";
		?>
		
		<div class="right">
			<div id="left-shadow"></div>
			<div class="welcome relative">
				<a id="click-drop"><span>Bonjour <?php echo $_SESSION['fname']?></span></a>
				<a type="button" class="deconnect" value="" name="deconnect" id="bien-deconnect" style="display:none;"/></a>
			</div>
			<div class="top-nav">
				<ul class="tabs">
					<li><a href="histoire.php?step=1" id="marie-1<?php echo($step==1?"_on":""); ?>">Le marié n&deg;1</a></li>
					<li><span class="bar"></span></li>
					<li><a href="histoire.php?step=2" id="marie-2<?php echo($step==2?"_on":""); ?>">Le marié n&deg;2</a></li>
					<li><span class="bar"></span></li>
					<li><a href="histoire.php?step=3" id="marie-3<?php echo($step==3?"_on":""); ?>">Les mariés</a></li>
				</ul>
			</div>
			<div class="title">
				<h2>Question <?php 
				if($step==1) echo "du marié n&deg;1";
				if($step==2) echo "du marié n&deg;2";
				if($step==3) echo "des mariés";
				?></h2>
				<p>Répondez à quelques questions croquantes de votre histoire.<br />
					Aidez les invités à mieux vous connaître ! Vos invités seront ravis !</p>
			</div>
			
			<form method="post" action="inc/<?php echo(($_SESSION[$id] != "")?"edithistoire.php":"addhistoire.php"); ?>" class="wedding_form relative" id="histoire-1" style="margin-left:0;">
			<div class="showText"></div>
			<?php
				for($i = 1; $i <= $rows; $i++){
				?>
				<div class="form_question_box">
					<div class="form_question">
					<?php if($i <= 4){ ?>
						<div class="form_select">
							<label>Question <?php echo $i; ?><span class="star">*</span></label>
							<input name="Question<?php echo $i; ?>" class="select_value" type="hidden" value="<?php echo $question[$i]; ?>"/>
							<p class="select_show">Séléctionnez vos question</p>
							<div class="select_options" style="display:none;">
								<a class="select_option" val="Q1">Q1<span class="selectable_opacity"></span></a>
								<a class="select_option" val="Q2">Q2<span class="selectable_opacity"></span></a>
								<a class="select_option" val="Q3">Q3<span class="selectable_opacity"></span></a>
								<a class="select_option" val="Q4">Q4<span class="selectable_opacity"></span></a>
							</div>
						</div>
						<?php
						} else { ?>
						<div class="form_text">
							<label>Question libre (Facultatif)</label>
							<input type="text" name="Question<?php echo $i; ?>"  placeholder="Ecrivez votre question" value="<?php echo $question[$i]; ?>"/>
						</div>
						<?php
						} ?>
						<div class="form_textarea">
							<label>Réponse</label>
							<textarea name="A<?php echo $i; ?>" cols="" rows=""><?php echo $answer[$i]; ?></textarea>
							<p class="below-desc">Champ libre</p>
						</div>
						<?php if($i > 4){ ?>
						<a class="btn-ques-cancel button">Annuler</a>
						<?php } ?>
					</div>
				</div>
				<?php
				}
			?>
				<div class="add-button-box">
					<a class="btn-ques-add button">Add</a>
					<p class="below-desc" >*Facultatif</p>
				</div>
				
				<input type="hidden" value="step-<?php echo $step; ?>" name="addhistoire-step" />
				<input type="submit" value="Valider le questionnaire" name="submit" class="btn-ques-valider button" style=""/>
		    </form>
			
		</div>
	</div>
</body>

</html>